package com.naiterui.ehp.bs.recommend.controller.medication;

import com.naiterui.common.repository.page.PageParamVO;
import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.recommend.service.ICommonPrescriptionService;
import com.naiterui.ehp.bs.recommend.vo.CommonPrescriptionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 常用处方
 *
 * @Author yangfuya
 */
@Slf4j
@Api(tags = SwaggerTag.DOCTOR + SwaggerTag.COMMON_PRESCRIPTION)
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "recommend/common/prescription")
public class CommonPrescriptionController {

    private final ICommonPrescriptionService commonPrescriptionService;

    @ApiOperation("分页列表")
    @GetMapping
    public PageVO<CommonPrescriptionVO> page(@RequestParam Long doctorId, PageParamVO pageVO) throws BusinessException {
        return commonPrescriptionService.page(doctorId, pageVO);
    }

    @ApiOperation("查看详情")
    @GetMapping("/detail")
    public CommonPrescriptionVO getById(@RequestParam Long doctorId, @RequestParam Long id) throws BusinessException {
        return commonPrescriptionService.getById(doctorId, id);
    }

    @ApiOperation("新增常用处方")
    @PostMapping
    public void save(@RequestParam Long doctorId, @Valid @RequestBody CommonPrescriptionVO commonPrescriptionVO)
        throws BusinessException {
        commonPrescriptionVO.setDoctorId(doctorId);
        commonPrescriptionService.saveOrUpdate(commonPrescriptionVO);
    }

    @ApiOperation("修改常用处方")
    @PostMapping("/update")
    public void update(@RequestParam Long doctorId, @Valid @RequestBody CommonPrescriptionVO commonPrescriptionVO)
        throws BusinessException {
        commonPrescriptionVO.setDoctorId(doctorId);
        commonPrescriptionService.saveOrUpdate(commonPrescriptionVO);
    }

    @ApiOperation("删除常用处方")
    @PostMapping("/delete")
    public void delete(@RequestParam Long doctorId, @RequestParam Long id) throws BusinessException {
        commonPrescriptionService.deleteById(doctorId, id);
    }

}
